package com.ygu.user.service.adapter;

import cn.hutool.core.util.RandomUtil;
import com.ygu.websocket.domain.entity.User;
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;

public class UserAdapter {
    public static User buildUserSave(String openId) {
        User user = new User();
        user.setOpenId(openId);
        return user;
    }

    public static User buildAuthorized(Long uid, WxOAuth2UserInfo userInfo) {
        User user = new User();
        user.setId(uid);
        user.setAvatar(userInfo.getHeadImgUrl());
        user.setName(userInfo.getNickname());
        user.setSex(userInfo.getSex());
        //这边需要对用户的Name判断是否过长 若过长的话则使用自己的微信昵称
        if(userInfo.getNickname().length()>6){
            user.setName("昵称过程"+ RandomUtil.randomInt(1000));
        } else {
            user.setName(userInfo.getNickname());
        }
        return user;
    }
}
